import com.atshiyou.bean.Student;
import com.atshiyou.dao.StudentDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

public class TestDao {
    public static void main(String[] args) {
        try {
            //1、获得SQLSession对象
            Reader reader = Resources.getResourceAsReader("mybatis.xml");
            SqlSession session = new SqlSessionFactoryBuilder().
                    build(reader,"development2").openSession();
            //2、得到要调用的方法
            StudentDao studentDao = session.getMapper(StudentDao.class);
            List<Student> all = studentDao.findAll();
            for(Student s:all){
                System.out.println(s);
            }
            //关闭资源
            reader.close();
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
